package servlet;

import Hadoop.HadoopUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

@WebServlet("/ReadServlet")
public class Read extends HttpServlet {

    public void init(HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        init(req,resp);
        String display="";
        String filePath=req.getParameter("filePath");

        HadoopUtil Url = new HadoopUtil();

        display = Url.hadoopRead(filePath);

        resp.setContentType("text/html;charset=utf-8");

        HttpSession session = req.getSession();

        req.setAttribute("obj_data",display);

        req.getRequestDispatcher("/read.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
